﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Diagnostics;
namespace Assignment_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

       private void Form1_Load(object sender, EventArgs e)
       {
          cboCountry.SelectedIndex = 0;
       }

       private void button2_Click(object sender, EventArgs e)
       {
           Application.Exit();
       }

       private void loadCity(string country)
       {
           lsbCity.Items.Clear();
           
           if (country == "ThaiLan")
           {
               lsbCity.Items.Add("Pattaya");
               lsbCity.Items.Add("ChiengMai");
               lsbCity.Items.Add("Bankok");
           }
           else
           {
               lsbCity.Items.Add("Ho Chi Minh");
               lsbCity.Items.Add("Nha Trang");
               lsbCity.Items.Add("Ha Noi");
           }
       }

       private void cboCountry_SelectedIndexChanged(object sender, EventArgs e)
       {
           string select = cboCountry.SelectedItem.ToString();
           loadCity(select);
       }

       private void txtEmpName_Leave(object sender, EventArgs e)
       {
           if (txtEmpName.Text.Trim() == "")
           {
               MessageBox.Show("Please enter employee name", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtEmpName.Focus();
              
           }
       }

       private void mskDayOfBirth_Leave(object sender, EventArgs e)
       {
           if (mskDayOfBirth.Text == "  /  /")
           {
               MessageBox.Show("Please enter day of birth", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               mskDayOfBirth.Focus();

           }
       }

       private void txtAddress_Leave(object sender, EventArgs e)
       {
           if (txtAddress.Text.Trim() == "")
           {
               MessageBox.Show("Please enter Address", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtAddress.Focus();

           }
       }

       private void cboCountry_Leave(object sender, EventArgs e)
       {
           if (cboCountry.SelectedItem.ToString() == "(Select)")
           {
               MessageBox.Show("Please choose country", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               cboCountry.Focus();

           }
       }

       private void lsbCity_Leave(object sender, EventArgs e)
       {
           int index = lsbCity.SelectedIndex;
           if (index < 0)
           {
               MessageBox.Show("Please choose City", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               lsbCity.Focus();
           }
       }

       private void lsbQuanti_Leave(object sender, EventArgs e)
       {
           int index = lsbQuanti.SelectedIndex;
           if (index < 0)
           {
               MessageBox.Show("Please choose Quantity", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               lsbQuanti.Focus();
           }
       }

       private void mskPhone_Leave(object sender, EventArgs e)
       {
           if (mskPhone.Text.Trim() == "-")
           {
               MessageBox.Show("Please enter Phone number", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               mskPhone.Focus();

           }
       }

       private void txtEmail_Leave(object sender, EventArgs e)
       {
           if (txtEmail.Text.Trim() == "")
           {
               MessageBox.Show("Please enter Email", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtEmail.Focus();

           }
       }

       private void mskDayJoin_Leave(object sender, EventArgs e)
       {
           if (mskDayJoin.Text == "  /  /")
           {
               MessageBox.Show("Please enter day of join", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               mskDayJoin.Focus();

           }
       }

       private void btnSubmit_Click(object sender, EventArgs e)
       {
           if (txtEmpName.Text.Trim() == "")
           {
               MessageBox.Show("Please enter employee name", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtEmpName.Focus();
               return;
           }

           if (mskDayOfBirth.Text == "  /  /")
           {
               MessageBox.Show("Please enter day of birth", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               mskDayOfBirth.Focus();
               return;
           }

           if (txtAddress.Text.Trim() == "")
           {
               MessageBox.Show("Please enter Address", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtAddress.Focus();
               return;
           }

           if (cboCountry.SelectedItem.ToString() == "(Select)")
           {
               MessageBox.Show("Please choose country", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               cboCountry.Focus();
               return;
           }

           int index = lsbCity.SelectedIndex;
           if (index < 0)
           {
               MessageBox.Show("Please choose City", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               lsbCity.Focus();
               return;
           }

           int index2 = lsbQuanti.SelectedIndex;
           if (index2 < 0)
           {
               MessageBox.Show("Please choose Quantity", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               lsbQuanti.Focus();
               return;
           }

           if (mskPhone.Text.Trim() == "-")
           {
               MessageBox.Show("Please enter Phone number", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               mskPhone.Focus();
               return;
           }

           if (txtEmail.Text.Trim() == "")
           {
               MessageBox.Show("Please enter Email", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtEmail.Focus();
               return;
           }

           if (mskDayJoin.Text == "  /  /")
           {
               MessageBox.Show("Please enter day of join", "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error);
               mskDayJoin.Focus();
               return;
           }

           string info = "";
           string name = txtEmpName.Text.Trim();
           string DoB = mskDayOfBirth.Text;
           string address = txtAddress.Text.Trim();
           string city = lsbCity.SelectedItem.ToString();
           string country = cboCountry.SelectedItem.ToString();
           string quanti = lsbQuanti.SelectedItem.ToString();
           string phone = mskPhone.Text;
           string email = txtEmail.Text.Trim();
           string DoJ = mskDayJoin.Text;

           info = " Employee name: " + name;
           info += "\n Day of Birth: " + DoB;
           info += "\n Address: " + address;
           info += "\n City: " + city;
           info += "\n Country: " + country;
           info += "\n Quantity: " + quanti;
           info += "\n Phone: " + phone;
           info += "\n Email: " + email;
           info += "\n Day of Join: " + DoJ;

           MessageBox.Show("Employee Detail: \n" + info, "Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Information);

       }

       private void llbLinkto_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
       {
           System.Diagnostics.Process.Start("http://www.vnexpress.net");
       }
    }
}
